package cn.wolfcode.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.Visit;
import cn.wolfcode.business.service.IVisitService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 拜访记录Controller
 * 
 * @author dalang
 * @date 2023-11-05
 */
@RestController
@RequestMapping("/business/visit")
public class VisitController extends BaseController
{
    @Autowired
    private IVisitService visitService;

    /**
     * 查询拜访记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:visit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Visit visit)
    {
        startPage();
        List<Visit> list = visitService.selectVisitList(visit);
        return getDataTable(list);
    }

    /**
     * 导出拜访记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:visit:export')")
    @Log(title = "拜访记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Visit visit)
    {
        List<Visit> list = visitService.selectVisitList(visit);
        ExcelUtil<Visit> util = new ExcelUtil<Visit>(Visit.class);
        util.exportExcel(response, list, "拜访记录数据");
    }

    /**
     * 获取拜访记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:visit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(visitService.selectVisitById(id));
    }

    /**
     * 新增拜访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visit:add')")
    @Log(title = "拜访记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Visit visit)
    {
        return toAjax(visitService.insertVisit(visit));
    }

    /**
     * 修改拜访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visit:edit')")
    @Log(title = "拜访记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Visit visit)
    {
        return toAjax(visitService.updateVisit(visit));
    }

    /**
     * 删除拜访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visit:remove')")
    @Log(title = "拜访记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(visitService.deleteVisitByIds(ids));
    }
}
